package georeduy.dao;

import java.util.List;

import georeduy.clases.Oferta;
import georeduy.clases.SitioInteres;
import georeduy.dao.interfaces.ISitioInteresDAO;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;


@Stateless(name = "SitioInteresDAO", mappedName = "GeoRed.uy-GeoRed.uy-JPA-SitioInteresDAO")
public class SitioInteresDAO
        implements  ISitioInteresDAO
{

    
    @PersistenceContext(unitName="Geored.uy-JPA")
    private EntityManager em;

    public SitioInteresDAO() {
    }

    public Object queryByRange(String jpqlStmt, int firstResult,
                               int maxResults) {
        Query query = em.createQuery(jpqlStmt);
        if (firstResult > 0) {
            query = query.setFirstResult(firstResult);
        }
        if (maxResults > 0) {
            query = query.setMaxResults(maxResults);
        }
        return query.getResultList();
    }


    public SitioInteres persistSitioInteres(SitioInteres sitioInteres) {
        em.persist(sitioInteres);
        return sitioInteres;    }

    public SitioInteres mergeSitioInteres(SitioInteres sitioInteres) {
        return em.merge(sitioInteres); }

 
    public void removeSitioInteres(SitioInteres sitioInteres) {
        sitioInteres = em.find(SitioInteres.class, sitioInteres.getNombre());
        em.remove(sitioInteres); }

	@Override
	public SitioInteres FindSitioxNombre(String nombre) {
		return em.find(SitioInteres.class, nombre);	}

	
	@Override
	public List<SitioInteres> ListarSI() {    

	 
	 String lista = "select u from SitioInteres u";		
		TypedQuery<SitioInteres> query = em.createQuery(lista,SitioInteres.class );
		List<SitioInteres>  l = query.getResultList();
		return l;
	}

	@Override
	public boolean existeSitio(String nombre) {
		// TODO Auto-generated method stub
	
		if (em.find(SitioInteres.class, nombre) != null) 
			return true;
			else 
			return false;
	}
		
		
	}


